home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PASCAL / 0189.ZIP / TRANSFER.PAS < prev   
Pascal/Delphi Source File  |  1986-02-09  |  28KB  |  787 lines

  1. (***************************************************************)
  2. (*                                                             *)
  3. (*        FILER A LA PASCAL DATA BASE SOURCE CODE FILE         *)
  4. (*                                                             *)
  5. (*        (C) 1985 by  John M. Harlan                          *)
  6. (*                     24000 Telegraph                         *)
  7. (*                     Southfield, MI. 48034                   *)
  8. (*                                                             *)
  9. (*     The FILER GROUP of programs is released on a "FREE      *)
  10. (*     SOFTWARE" basis.  The recipient is free to examine      *)
  11. (*     and use the software with the understanding that if     *)
  12. (*     the FILER GROUP of programs prove to be of use and      *)
  13. (*     value,  a contribution to the author is encouraged.     *)
  14. (*                                                             *)
  15. (*     While reasonable effort has been made to ensure the     *)
  16. (*     reliability of the FILER GROUP of programs, no war-     *)
  17. (*     ranty is given. The recipient uses the programs at      *)
  18. (*     his own risk  and in no event shall the author be       *)
  19. (*     liable for damages arising from their use.              *)
  20. (*                                                             *)
  21. (*                                                             *)
  22. (***************************************************************)
  23.  
  24.  
  25. program transfer;  { ONE OF THE FILER GROUP OF PROGRAMS }
  26. {  PROGRAM TO TRANSFER DATA FROM ONE FILER DATA FORMAT  }
  27. {  TO A SECOND FILER DATA FORMAT                        }
  28. {  TRANSFER.PAS  REVISION 2.0 }
  29. {  INCLUDE FILES : TRANSFR1.PAS }
  30. {  JUNE 24, 1985 }
  31.  
  32. { Formatted 2/7/86 by Doug Stevens using Pformat and the Turbo
  33.   editors global search/replace. Original version was 100%
  34.   upper case and very hard to read. }
  35.  
  36. label  QUIT;
  37.  
  38. type
  39.   Range            = array[1..256] of char;
  40.   String60         =  string[60];
  41.   String20         =  string[20];
  42.   NameStr          =  string[12];
  43.  
  44. var
  45.   filerecchgd      : boolean;    { FOR SOURCE FILE }
  46.   recaddedtofile   : boolean;    { FOR SOURCE FILE }
  47.   filerecchgd2     : boolean;    { FOR DESTINATION FILE }
  48.   recaddedtofile2  : boolean;    { FOR DESTINATION FILE }
  49.   fileexists       : boolean;
  50.   nullrecord       : boolean;
  51.   exitflag         : boolean;
  52.  
  53.   ch               : char;
  54.  
  55.   filename,filename2         : string[6];
  56.   filedate,filedate2,
  57.   currdate                   : string[8];
  58.   sourcename                 : string[14];
  59.   sourcenamedat              : string[14];
  60.   destinationname            : string[14];
  61.   destinationnamedat         : string[14];
  62.  
  63.   ans                        : String60;
  64.   message                    : String60;
  65.   thiskey                    : String60;
  66.  
  67.    w, x, y, z, code, first, len,
  68.   maxnbrrec, rcdlen, destfieldnbr,
  69.   blockingfactor, fieldperrecord,
  70.   ascii, keylength, destnbr             : integer;
  71.  
  72.   w2, x2, y2, z2, code2, first2, len2,
  73.   maxnbrrec2, rcdlen2,
  74.   blockingfactor2, fieldperrecord2,
  75.   ascii2, keylength2                    : integer;
  76.  
  77.   datarecord, diskrecord, precbyte,
  78.   diskrecnowinmem, nbrdiskrecused,
  79.   nbrrecused,lastrecused                : integer;  { FOR SOURCE FILE }
  80.  
  81.   datarecord2, diskrecord2, precbyte2,
  82.   diskrecnowinmem2, nbrdiskrecused2,
  83.   nbrrecused2,lastrecused2              : integer;  { FOR DESTINATION FILE }
  84.  
  85.   numvalue                              :    real;
  86.  
  87.   labellength, datalen, dataform,
  88.   labelposn, dataposn, row, column      :    array[1..32] of integer;
  89.  
  90.   labellength2, datalen2, dataform2,
  91.   labelposn2, dataposn2, row2,
  92.   column2, transarray                   :    array[1..32] of integer;
  93.  
  94.   keyfield                              :    array[0..10] of integer;
  95.   lbl,lbl2                              :    array[1..384] of char;
  96.   getdata                               :    Range;  { FOR SOURCE FILE }
  97.   getdata2                              :    Range;  { FOR DESTINATION FILE }
  98.  
  99.   source                                :    file;
  100.   destination                           :    file;
  101.  
  102.  
  103. {================================================================}
  104. {        BINARY CODED DECIMAL TO INTEGER FUNCTION                }
  105. {================================================================}
  106. function BcdToInt (cha : char) : integer;
  107. begin
  108.   BcdToInt := ord(cha) - trunc(ord(cha)/16)*6;
  109. end;
  110. {================================================================}
  111. {             CHARACTER TO INTEGER FUNCTION                      }
  112. {================================================================}
  113. function ChrToInt(var charray : Range; start, len : integer)  : integer;
  114. var
  115.   code, result : integer;
  116.   workstring   : string[10];
  117. begin
  118.   workstring := '';
  119.   for result := 0 to len-1  do
  120.     begin
  121.       if charray[start + result ] = ' ' then
  122.         workstring := workstring + '0'
  123.       else workstring := workstring + charray[start+result];
  124.     end;
  125.   val(workstring,result,code);
  126.   ChrToInt := result;
  127. end;
  128. {================================================================}
  129. {               TIDE (EDIT BACKWARDS) PROCEDURE                  }
  130. {================================================================}
  131. procedure Tide( var message : String60);
  132. var w  :  integer;
  133. begin
  134.   for w := length(message) downto 1 do
  135.     begin
  136.       if message[w] in [',', '$', '+'] then
  137.         begin
  138.           delete(message,w,1);
  139.           message := ' ' + message;
  140.         end;
  141.     end;
  142. end;
  143. {===============================================================}
  144. {                      FUNCTION EDITNBR                         }
  145. {===============================================================}
  146. function EditNbr(x: real; y,z: integer; dollar: char ) : String20;
  147. var
  148.   numstring : string[24];
  149. begin    { CONVERT THE REAL NUMBER TO A STRING VALUE }
  150.   str(x:18:z,numstring);
  151.   if z = 0 then z := 16  { FIRST POSSIBLE COMMA LOCATION  }
  152.   else z := pos('.',numstring)-3;  {    DITTO             }
  153.  
  154.   while z > 1 do  {  INSERT COMMAS/SPACES IN THE NUMBER  }
  155.     begin
  156.       if numstring[z-1] in [' ','-'] then
  157.         insert(' ',numstring,z)
  158.       else insert(',',numstring,z);
  159.       z := z -3 ;  {  COMMAS OCCUR EVERY THIRD CHARACTER  }
  160.     end;
  161.  
  162.   {  FIND THE FIRST NON SPACE CHARACTER IN THE NUMBER }
  163.   z := 0;
  164.   repeat
  165.     z := z + 1;
  166.  until numstring[z] <> ' ';
  167.  
  168.   { DELETE ANY SPACE FOLLOWING A MINUS SIGN }
  169.   if numstring[z] = '-' then
  170.     begin
  171.       if numstring[z+1] = ' ' then delete(numstring,z+1,1);
  172.       if dollar = '$' then insert('$',numstring,z+1);
  173.     end
  174.  
  175.   { ADD THE $/SPACE CHARACTER TO THE BEGINNING OF THE NUMBER }
  176.   else numstring[z-1] := dollar;
  177.  
  178.   { REPLACE THE NUMBER WITH A FIELD OF '<' IF IT IS TOO BIG  }
  179.   z := length(numstring)-y;
  180.   if numstring[z-1] = '-' then
  181.       for z := y downto 0 do numstring[z] := '<'
  182.   else
  183.     begin
  184.       if numstring[z] in ['0'..'9',',','-','.'] then
  185.           for z := y downto 0 do numstring[z] := '<';
  186.     end;
  187.   EditNbr := copy(numstring,z+1,y);
  188.  
  189. end;
  190. {================================================================}
  191. {               STRING TO REAL NUMBER PROCEDURE                  }
  192. {================================================================}
  193. procedure StringToReal(var source:String60;var numb:real;var code:integer);
  194. var
  195.   w  :  integer;
  196.   condition  :  boolean;
  197. begin
  198.   w := 1;
  199.   numb := 0;
  200.   condition := true;
  201.   Tide(source); { ELIMINATE PUNCTUATION }
  202.   repeat  { UNTIL CONDITION = FALSE }
  203.     if source[w] = ' ' then delete(source,1,1)
  204.     else condition := false;
  205.     if length(source) = 0 then
  206.       begin
  207.         source := '0';
  208.         condition := false;
  209.       end;
  210.   until condition = false;
  211.   if length(source) = 1 then condition := true;
  212.   while condition = false do
  213.     begin
  214.       if source[w] = ' ' then
  215.         begin
  216.           condition := true;
  217.           w := w-2;
  218.         end;
  219.       if length(source) = w then
  220.         begin
  221.           condition := true;
  222.           w := w-1;
  223.         end;
  224.       w := w + 1;
  225.     end;
  226.   source := copy(source,1,w);
  227.   val( source,numb,code );
  228. end;
  229. {================================================================}
  230. {           CALCULATE DISKRECORD & PRECBYTE PROCEDURE            }
  231. {================================================================}
  232. procedure Calculate;
  233.   begin
  234.     diskrecord := trunc((datarecord-1)/blockingfactor)*2+7;
  235.     precbyte := ((datarecord-1) mod blockingfactor)*rcdlen;
  236.   end;
  237. {================================================================}
  238. {                   GET DATA RECORD PROCEDURE                    }
  239. {================================================================}
  240. procedure GetDataRec;
  241.   begin
  242.     Calculate;
  243.     if diskrecord <> diskrecnowinmem then
  244.       begin
  245.         if filerecchgd = true then
  246.           begin
  247.             if diskrecnowinmem > nbrdiskrecused then
  248.               begin                 { GET NEXT AVAILABLE RECORD }
  249.                 Seek(source,nbrdiskrecused+2);
  250.                 nbrdiskrecused := diskrecnowinmem;
  251.               end
  252.             else
  253.               begin
  254.                 Seek(source,diskrecnowinmem);
  255.               end;
  256.             blockwrite(source,getdata,2);  {SAVE CHANGED DATA}
  257.             filerecchgd := false;
  258.           end;
  259.         if diskrecord <= nbrdiskrecused then
  260.           begin
  261.             Seek(source,diskrecord);
  262.             blockread(source,getdata,2);         {  RECORD DATA  }
  263.           end
  264.         else FillChar(getdata[1],256,' '); {SPACES FOR EMPTY REC }
  265.         diskrecnowinmem := diskrecord;
  266.       end;
  267.   end;
  268. {================================================================}
  269. {     CALCULATE DESTINATION DISKRECORD & PRECBYTE PROCEDURE      }
  270. {================================================================}
  271. procedure Calculate2;
  272.   begin
  273.     diskrecord2 := trunc((datarecord2-1)/blockingfactor2)*2+7;
  274.     precbyte2 := ((datarecord2-1) mod blockingfactor2)*rcdlen2;
  275.   end;
  276. {================================================================}
  277. {            GET DESTINATION DATA RECORD PROCEDURE               }
  278. {================================================================}
  279. procedure GetDataRec2;
  280.   begin
  281.     Calculate2;
  282.     if diskrecord2 <> diskrecnowinmem2 then
  283.       begin
  284.         if filerecchgd2 = true then
  285.           begin
  286.             if diskrecnowinmem2 > nbrdiskrecused2 then
  287.               begin                 { GET NEXT AVAILABLE RECORD }
  288.                 Seek(destination,nbrdiskrecused2+2);
  289.                 nbrdiskrecused2 := diskrecnowinmem2;
  290.               end
  291.             else
  292.               begin
  293.                 Seek(destination,diskrecnowinmem2);
  294.               end;
  295.             blockwrite(destination,getdata2,2);  {SAVE CHANGED DATA}
  296.             filerecchgd2 := false;
  297.           end;
  298.         if diskrecord2 <= nbrdiskrecused2 then
  299.           begin
  300.             Seek(destination,diskrecord2);
  301.             blockread(destination,getdata2,2);         {  RECORD DATA  }
  302.           end
  303.         else FillChar(getdata2[1],256,' '); {SPACES FOR EMPTY REC }
  304.         diskrecnowinmem2 := diskrecord2;
  305.       end;
  306.   end;
  307. {================================================================}
  308. {               GET DATA FROM ARRAY PROCEDURE                    }
  309. {================================================================}
  310. procedure GetDataFromArray(var message : String60; z : integer);
  311. var w :  integer;
  312. begin
  313.   message := '';
  314.   for w := precbyte+dataposn[z] to precbyte+dataposn[z+1]-1 do
  315.     message := message + getdata[w];
  316. end;
  317. {================================================================}
  318. {                 PRINT LABEL AND FIELD NUMBER                   }
  319. {================================================================}
  320. procedure PrintLabFldNbr( z: integer);
  321. var
  322.   w      :  integer;
  323. begin
  324.   if row[z] <22 then
  325.     begin
  326.       GotoXY(column[z],row[z]);
  327.       for w := labelposn[z] to labelposn[z+1]-1 do
  328.       write (lbl[w]);
  329.       write('= ',z);
  330.     end;
  331. end;
  332. {================================================================}
  333. {                      PRINT LABEL                               }
  334. {================================================================}
  335. procedure PrintLabel( z: integer);
  336. var
  337.   w      :  integer;
  338. begin
  339.   write(z,' : ');
  340.   for w := labelposn[z] to labelposn[z+1]-1 do
  341.   write (lbl[w]);
  342.   writeln;
  343. end;
  344. {================================================================}
  345. {              DISPLAY ONE RECORD PROCEDURE, SOURCE              }
  346. {================================================================}
  347. procedure DisplayRec;
  348. begin
  349.   ClrScr;
  350.   for z := 1 to fieldperrecord do
  351.   PrintLabFldNbr(z);
  352.   GotoXY(70,23);
  353.   write('RECORD ',datarecord);
  354.   lastrecused := datarecord;
  355. end;
  356.  
  357. {================================================================}
  358. {               GET DATA FROM ARRAY2 PROCEDURE                   }
  359. {================================================================}
  360. procedure GetDataFromArray2(var message : String60; z : integer);
  361. var w :  integer;
  362. begin
  363.   message := '';
  364.   for w := precbyte2+dataposn2[z] to precbyte2+dataposn2[z+1]-1 do
  365.     message := message + getdata2[w];
  366. end;
  367. {================================================================}
  368. {        PRINT DESTINATION LABEL AND FIELD NUMBER                }
  369. {================================================================}
  370. procedure PrintLabFldNbr2( z: integer);
  371. var
  372.   w      :  integer;
  373. begin
  374.   if row2[z] <22 then
  375.     begin
  376.       GotoXY(column2[z],row2[z]);
  377.       for w := labelposn2[z] to labelposn2[z+1]-1 do
  378.       write (lbl2[w]);
  379.       write('= ',z);
  380.     end;
  381. end;
  382. {================================================================}
  383. {                PRINT DESTINATION LABEL                         }
  384. {================================================================}
  385. procedure PrintLabel2( z: integer);
  386. var
  387.   w      :  integer;
  388. begin
  389.   write(z,' : ');
  390.   for w := labelposn2[z] to labelposn2[z+1]-1 do
  391.   write (lbl2[w]);
  392.   writeln;
  393. end;
  394. {================================================================}
  395. {           DISPLAY ONE RECORD PROCEDURE, DESTINATION            }
  396. {================================================================}
  397. procedure DisplayRec2;
  398. begin
  399.   ClrScr;
  400.   for z := 1 to fieldperrecord2 do
  401.   PrintLabFldNbr2(z);
  402.   GotoXY(70,23);
  403.   write('RECORD ',datarecord2);
  404.   lastrecused2 := datarecord2;
  405. end;
  406. {===============================================================}
  407. {                       FUNCTION EXIST                          }
  408. {===============================================================}
  409. function Exist(filename : NameStr) : boolean;
  410. var
  411.   fil    :  file;
  412.   status : Integer;
  413.  
  414. begin
  415.   Assign(fil,filename);
  416.   {$I-}
  417.   reset(fil);
  418.   {$I+}
  419.   Exist := (IOResult = 0);
  420. {$I-} Close(fil); status := IOResult; {$I+} (* Required by Turbo 3.x *)
  421. end;                                        (* Added by Doug Stevens *)
  422. {================================================================}
  423. {           FUNCTION GET NUMBER IN GETDATA FIELD ( Z )           }
  424. {================================================================}
  425. function FnbrInFld(z : integer) : real;
  426. var
  427.   realval : real;
  428.   begin
  429.     GetDataFromArray(ans,z);
  430.     if dataform[z] <> ascii then
  431.       StringToReal(ans,realval,code)
  432.     else realval := 0;
  433.     FnbrInFld := realval;
  434.   end;
  435.  
  436. {================================================================}
  437. {            STORE DATA IN ARRAY GETDATA PROCEDURE               }
  438. {================================================================}
  439. procedure StoreDataInArray2 (z : integer);
  440. begin
  441.   first := 1;
  442.   if dataform2[z] <> ascii then
  443.     begin
  444.       StringToReal(ans,numvalue,code);
  445.       str(numvalue:20:8,ans);
  446.       ans := ans + '                                            ';
  447.       first := pos('.',ans) - datalen2[z];
  448.       if dataform2[z] <> 0 then first := first + dataform2[z] + 1;
  449.       if dataform2[z] = ascii then first := 1;
  450.     end;
  451.   FillChar(getdata2[precbyte2+dataposn2[z]],datalen2[z],' ');
  452.   Move(ans[first],getdata2[precbyte2+dataposn2[z]],datalen2[z]);
  453. end;
  454. {================================================================}
  455. {                  INITIALIZE FILER FILE                         }
  456. {================================================================}
  457. procedure Initialize;
  458.   label  QUIT;
  459.  
  460. begin
  461.   repeat
  462.     ClrScr; exitflag := FALSE;
  463.     TextMode(bw40);
  464.     GotoXY(1,22);
  465.     write('TRANSFER A LA PASCAL');
  466.     GotoXY(1,23);
  467.     write('ENTER SOURCE FILE NAME : ');
  468.     readln(sourcename);
  469.     x := pos('.',sourcename);
  470.     if x <> 0 then sourcename := copy(sourcename,1,x-1);
  471.     if sourcename = 'END' then
  472.       begin                     { Quick and dirty exit. }
  473.         exitflag := TRUE;
  474.         goto QUIT;
  475.       end;
  476.     sourcenamedat := sourcename + '.DAT';
  477.     fileExists := Exist(sourcenamedat);
  478.   until fileexists = true;
  479.   writeln;
  480.   writeln;
  481.  
  482.   repeat
  483.     GotoXY(1,23);
  484.     write('ENTER DESTINATION FILE NAME : ');
  485.     readln(destinationname);
  486.     x := pos('.',destinationname);
  487.     if x <> 0 then destinationname := copy(destinationname,1,x-1);
  488.     destinationnamedat := destinationname + '.DAT';
  489.     fileexists := exist(destinationnamedat);
  490.   until fileexists = true;
  491.  
  492.  
  493.   {=======================================}
  494.   {   CREATE SOURCE & DESTINATION FILE    }
  495.   {=======================================}
  496.   Assign(source,sourcenamedat);
  497.   reset(source);
  498.  
  499.   Assign(destination, destinationnamedat);
  500.   reset ( destination );
  501.  
  502.   {=======================================}
  503.   {        BUILD HEADER FOR SOURCE        }
  504.   {=======================================}
  505.   Seek(source,0);
  506.   blockread( source,getdata,1 );          { BASIC/Z BLOCK 0 }
  507.   blockread( source,getdata,1 );          { FILE PARAMETERS }
  508.   blockread( source,lbl,3 );                 { FILER LABELS }
  509.  
  510.  
  511.   {=================================================}
  512.   {      READ IN HEADER DATA FOR FILER FILE         }
  513.   {=================================================}
  514.   filename := 'XXXXXX';
  515.   for x := 1 to 6 do
  516.     filename[x] := getdata[x];
  517.   maxnbrrec := ChrToInt(getdata,7,4);
  518.   nbrrecused := ChrToInt(getdata,11,4);
  519.   rcdlen := ChrToInt(getdata,15,3);
  520.   blockingfactor := ChrToInt(getdata,18,2);
  521.   fieldperrecord := ChrToInt(getdata,20,2);
  522.   filedate := '  /  /  ';
  523.   Move(getdata[22],filedate[1],8);
  524.  
  525. {================================================================}
  526. {  GET LABEL LENGTH, DATA LENGTH & DATA FORM INFO                }
  527. {================================================================}
  528.  
  529. labelposn[1] := 1;
  530. dataposn[1] := 1;
  531.  
  532. for x := 1 to fieldperrecord do
  533.   begin
  534.     labellength[x] :=  BcdToInt(getdata[32+x]);
  535.     datalen[x]     :=  BcdToInt(getdata[64+x]);
  536.     dataform[x]    :=  ord(getdata[96+x])-48;
  537.     labelposn[x+1] :=  labelposn[x] + labellength[x];
  538.     dataposn[x+1]  :=  dataposn[x] + datalen[x];
  539.   end;
  540.  
  541. {================================================================}
  542. {           TRANSLATE REPORT STRUCTURE                           }
  543. {================================================================}
  544.  
  545.   blockread(source,getdata,1);  { SCREEN INFORMATION }
  546.       { ESTABLISH VALUE OF DATAFORM[Z] FOR ASCII INFORMATION }
  547.       if getdata[1] = 'S' then ascii := 9 else ascii := 15;
  548.   for x := 1 to fieldperrecord do
  549.     begin
  550.       w := x*4+1;
  551.       row[x]       := BcdToInt(getdata[w]);
  552.       column[x] := BcdToInt(getdata[w+1])*10+trunc(BcdToInt(getdata[w+2])/10);
  553.       {FIELDNBR[X]  := BCDTOIN(GETDATA[W+3]);} { not implemented }
  554.     end;
  555.   blockread(source,getdata,2);  { REPORT FORMAT INFORMATION (NOT USED) }
  556.  
  557.  
  558.   {============================================}
  559.   {        BUILD HEADER FOR DESTINATION        }
  560.   {============================================}
  561.   Seek(destination,0);
  562.   blockread( destination,getdata2,1 );          { BASIC/Z BLOCK 0 }
  563.   blockread( destination,getdata2,1 );          { FILE PARAMETERS }
  564.   blockread( destination,lbl2,3 );                 { FILER LABELS }
  565.  
  566.  
  567.   {=================================================}
  568.   {      READ IN HEADER DATA FOR FILER FILE         }
  569.   {=================================================}
  570.   filename := 'XXXXXX';
  571.   for x := 1 to 6 do
  572.     filename2[x] := getdata2[x];
  573.   maxnbrrec2 := ChrToInt(getdata2,7,4);
  574.   nbrrecused2 := ChrToInt(getdata2,11,4);
  575.   rcdlen2 := ChrToInt(getdata2,15,3);
  576.   blockingfactor2 := ChrToInt(getdata2,18,2);
  577.   fieldperrecord2 := ChrToInt(getdata2,20,2);
  578.   filedate2 := '  /  /  ';
  579.   Move(getdata2[22],filedate2[1],8);
  580.  
  581. {================================================================}
  582. {  GET LABEL LENGTH, DATA LENGTH & DATA FORM INFO                }
  583. {================================================================}
  584.  
  585. labelposn2[1] := 1;
  586. dataposn2[1] := 1;
  587.  
  588. for x := 1 to fieldperrecord2 do
  589.   begin
  590.     labellength2[x] :=  BcdToInt(getdata2[32+x]);
  591.     datalen2[x]     :=  BcdToInt(getdata2[64+x]);
  592.     dataform2[x]    :=  ord(getdata2[96+x])-48;
  593.     labelposn2[x+1] :=  labelposn2[x] + labellength2[x];
  594.     dataposn2[x+1]  :=  dataposn2[x] + datalen2[x];
  595.   end;
  596.  
  597. {================================================================}
  598. {           TRANSLATE REPORT STRUCTURE                           }
  599. {================================================================}
  600.  
  601.   blockread(destination,getdata2,1);  { SCREEN INFORMATION }
  602.       { ESTABLISH VALUE OF DATAFORM[Z] FOR ASCII INFORMATION }
  603.       if getdata2[1] = 'S' then ascii := 9 else ascii := 15;
  604.   for x := 1 to fieldperrecord2 do
  605.     begin
  606.       w := x*4+1;
  607.       row2[x]       := BcdToInt(getdata2[w]);
  608.       column2[x] := BcdToInt(getdata2[w+1])*10+trunc(BcdToInt(getdata2[w+2])/10);
  609.       {FIELDNBR2[X]  := BCDTOIN(GETDATA2[W+3]);} { not implemented }
  610.     end;
  611.   blockread(destination,getdata2,2);  { REPORT FORMAT INFORMATION (NOT USED) }
  612.  
  613. {================================================================}
  614. {          INITIALIZE VARIABLES FOR ENTRY INTO FILER             }
  615. {================================================================}
  616.   datarecord := nbrrecused;                 { SOURCE FILE SET UP }
  617.   Calculate;
  618.   diskrecnowinmem := diskrecord -1; { ENSURE DISK READ FIRST TIME}
  619.   filerecchgd := false;      { ENSURE NO WRITE BEFORE FIRST READ }
  620.   lastrecused := 0;               { SET LAST RECORD USED TO ZERO }
  621.   nbrdiskrecused := diskrecord;     { ESTABLISH MAX DISK REC NBR }
  622.   recaddedtofile := false; { FLAG TO INDICATE CHANGE IN FILE SIZE}
  623. {================================================================}
  624. {        INITIALIZE VARIABLES FOR ENTRY INTO DESTINATION         }
  625. {================================================================}
  626.   datarecord2 := nbrrecused2;          { DESTINATION FILE SET UP }
  627.   Calculate2;
  628.   diskrecnowinmem2 := diskrecord2 -1; { ENSURE DISK READ FIRST TIME}
  629.   filerecchgd2 := false;       { ENSURE NO WRITE BEFORE FIRST READ }
  630.   lastrecused2 := 0;                { SET LAST RECORD USED TO ZERO }
  631.   nbrdiskrecused2 := diskrecord2;     { ESTABLISH MAX DISK REC NBR }
  632.   recaddedtofile2 := false;  { FLAG TO INDICATE CHANGE IN FILE SIZE}
  633. QUIT:
  634. end;  { INTIIALIZE PROCEDURE }
  635.  
  636. {================================================================}
  637. {                     TRANSFER PROGRAM                           }
  638. {================================================================}
  639.  
  640. begin
  641.   Initialize;                   { ID AND READ IN FILE PARAMETERS }
  642.   if exitflag then goto QUIT;   { Quick and dirty exit. }
  643.   TextMode(bw80);
  644.  
  645.   {======================================}
  646.   {        BUILD TRANSLATE ARRAY         }
  647.   {======================================}
  648.   repeat
  649.     DisplayRec2;   { DISPLAY DESTINATION FILER FILE }
  650.     for x := 1 to 31 do
  651.       transarray[x] := 0;
  652.     x := 1;
  653.     repeat
  654.       GotoXY(1,22);
  655.       write('NAME OF SOURCE FIELD TO BE TRANSLATED  : ');
  656.       ClrEol;
  657.       TextColor(yellow);
  658.       TextBackGround(blue);
  659.       for w := labelposn[x] to labelposn[x+1]-1 do { WRITE LABEL }
  660.         write(lbl[w]);
  661.       TextColor(white);
  662.       TextBackGround(black);
  663.       GotoXY(1,23);
  664.       write('ENTER DESTINATION FIELD NUMBER (ABOVE) : ');
  665.       ClrEol;
  666.       ans := '';
  667.       read(ans);
  668.       if length(ans) = 0 then
  669.         begin
  670.           ans := '0';
  671.         end;
  672.       if (ans = '-') and (x>1) then x := pred(x)
  673.       else
  674.         begin
  675.           val(ans,destfieldnbr,code);
  676.           if code = 0 then
  677.             begin
  678.               transarray[x] := destfieldnbr;
  679.               x := succ(x);
  680.             end
  681.           else transarray[x] := 0;
  682.         end;
  683.     until x > fieldperrecord;
  684.  
  685.     ClrScr;
  686.     for x := 1 to fieldperrecord do
  687.       begin
  688.         write(x:3,'  ===>',transarray[x]:3,'   |  ');
  689.         for w := labelposn[x] to labelposn[x+1]-1 do
  690.               write (lbl[w]);
  691.         write(' ===> ');
  692.         if transarray[x] <> 0 then
  693.           begin
  694.             for w := labelposn2[transarray[x]] to labelposn2[transarray[x]+1]-1 do
  695.               write(lbl2[w]);
  696.           end;
  697.         writeln;
  698.       end;
  699.     writeln;
  700.     write('IS TRANSFER TABLE OK (Y/N) : ');
  701.     readln(ch);
  702.     ch := UpCase(ch);
  703.     if ch <> 'N' then ch := 'Y';
  704.   until ch = 'Y';
  705.   writeln;
  706.   write('PRINT HARD COPY OF TRANSFER TABLE (Y/N) ? : ');
  707.   readln(ch);
  708.   ch := UpCase(ch);
  709.   if ch = 'Y' then
  710.   begin
  711.     writeln('ENERGIZE AND SELECT PRINTER FOR HARD COPY');
  712.     writeln('DEPRESS ANY KEY WHEN READY.');
  713.     read(Kbd,ch);
  714.     writeln;
  715.     writeln('..... PRINTING......');
  716.  
  717.     writeln(Lst,'             TRANSLATION TABLE');
  718.     writeln(Lst);
  719.     writeln(Lst,'OLD      NEW      OLD LABEL ==> NEW LABEL');
  720.     writeln(Lst,'FLD #    FLD #');
  721.     writeln(Lst);
  722.     for x := 1 to fieldperrecord do
  723.       begin
  724.         write(Lst,x:3,'  ===>',transarray[x]:3,'   |  ');
  725.         for w := labelposn[x] to labelposn[x+1]-1 do
  726.               write(Lst,lbl[w]);
  727.         write(Lst,' ===> ');
  728.         if transarray[x] <> 0 then
  729.           begin
  730.             for w := labelposn2[transarray[x]] to labelposn2[transarray[x]+1]-1 do
  731.               write(Lst,lbl2[w]);
  732.           end;
  733.         writeln(Lst);
  734.       end;
  735.     writeln(Lst,^l);
  736.   end;
  737.  
  738.   ClrScr;
  739.   GotoXY(1,20);
  740.   writeln('TRANSFER A LA PASCAL');               { TRANSFER DATA }
  741.   write('====================');
  742.   for datarecord := 1 to nbrrecused do
  743.     begin
  744.       GetDataRec;    { GET SOURCE DATA RECORD }
  745.       datarecord2 := datarecord;
  746.       GetDataRec2;   { GET DESTINATION DATA RECORD }
  747.       for destnbr := 1 to fieldperrecord do
  748.         begin
  749.           w := transarray[destnbr];
  750.           if w <> 0 then
  751.             begin
  752.               GetDataFromArray(ans,destnbr);
  753.               ans := ans + '                                     ';
  754.               StoreDataInArray2(w);
  755.             end;
  756.           filerecchgd2 := true;
  757.         end;
  758.         GotoXY(1,23);
  759.         write(datarecord,' OF ',nbrrecused,' RECORDS TRANSFERED.');
  760.     end;
  761.  
  762. {================================================================}
  763. {                    END PROGRAM                                 }
  764. {================================================================}
  765. if filerecchgd2 = true then  { ENSURE LAST RECORD IS WRITTEN TO DISK }
  766.   begin
  767.     Seek(destination,diskrecnowinmem2);
  768.     blockwrite(destination,getdata2,2);
  769.   end;
  770.  
  771. Seek(destination,1);                 { UPDATE NUMBER OF RECORDS }
  772. blockread(destination,getdata2,1);
  773.  
  774. writeln;
  775. writeln;
  776. writeln('HAVE A GREAT DAY!');
  777.  
  778. str(nbrrecused:4,ans);                {  ENTER NUMBER OF RECORDS  }
  779. Move(ans[1],getdata2[11],4);          { IN FILER FILE HEADER INFO }
  780. Seek(destination,1);
  781. blockwrite(destination,getdata2,1);
  782.  
  783. close(source);
  784. close(destination);
  785. QUIT:
  786. end.
  787.